package com.isoft.systemprovidor.service.perinfor;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.isoft.systemprovidor.bean.ResponseData;
import com.isoft.systemprovidor.bean.ResultCode;
import com.isoft.systemprovidor.dao.perinfor.Perinfor_Documentinfo_Dao;
import com.isoft.systemprovidor.entity.perinfor.Perinfor_Basic;
import com.isoft.systemprovidor.entity.perinfor.Perinfor_Documentinfo;
import com.isoft.systemprovidor.util.IdUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class Perinfor_Documentinfo_Service {
    @Autowired
    Perinfor_Documentinfo_Dao perinfor_documentinfo_dao;
    /*查看我的证件信息*/
    public ResponseData selectDocumentinfo(String sysuserid){
        ResponseData responseData =new ResponseData();
        if (sysuserid.isEmpty()|| null == sysuserid){
            responseData.setErrorCode(ResultCode.PARAM_IS_BLANK.getCode());
            responseData.setMsg(ResultCode.PARAM_IS_BLANK.getMessage());
            return responseData;
        }
        QueryWrapper wrapper = new QueryWrapper<>();
        wrapper.eq("sysuserid",sysuserid);
        wrapper.eq("islock",0);
        responseData.setErrorCode(ResultCode.SUCCESS.getCode());
        responseData.setMsg(ResultCode.SUCCESS.getMessage());
        responseData.setData(perinfor_documentinfo_dao.selectList(wrapper));
        return responseData;
    }

    /*修改我的证件信息*/
    public boolean changeDocumentinfo(Perinfor_Documentinfo perinforDocumentinfo){
        if((null == perinforDocumentinfo)||(!IdUtil.idCheck(perinforDocumentinfo.getId()))||(perinforDocumentinfo.getSysuserid().isEmpty())){
            return false;
        }
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("sysuserid",perinforDocumentinfo.getSysuserid());
        wrapper.eq("id",perinforDocumentinfo.getId());
        return perinfor_documentinfo_dao.update(perinforDocumentinfo,wrapper)>0;
    }
    /*添加我的证件信息*/
    public boolean insertDocumentinfo(Perinfor_Documentinfo perinforDocumentinfo){
        if((null == perinforDocumentinfo)||(perinforDocumentinfo.getSysuserid().isEmpty())){
            return false;
        }
        return perinfor_documentinfo_dao.insert(perinforDocumentinfo)>0;
    }


    /*删除自己个人基础信息*/
    public boolean deleteDocumentinfo( Integer id ,String sysuserid){
        if (id==null|| sysuserid.isEmpty()){
            return false;
        }
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("id",id);
        wrapper.eq("sysuserid",sysuserid);
        return perinfor_documentinfo_dao.delete(wrapper)>0;

    }
}
